<template>
  <div class="content-block block---3">
    <div class="info-head">{{ title }}</div>
    <div class="info-content">
      <v-chart
        ref="chart"
        :option="chartOption" style="width:100%;height:360px;"
        :theme="chartTheme" autoresize
      ></v-chart>
    </div>
  </div>
</template>

<script>
import MixinChartOptionToolbox from '@/mixins/chart-option-toolbox';
import BarClickListener from '@/mixins/bar-click-listener'

import { defaultNumber } from '@/utils';
import MixinVchartTheme from '@/mixins/mixin-vchart-theme';

export default {
  name: 'grid-item-three',
  mixins: [BarClickListener, MixinChartOptionToolbox, MixinVchartTheme],
  props: {
    data: {
      type: Object,
      default () {
        return {};
      }
    },
  },
  data () {
    return {
      barClickHandlerKey: 'industryCode',
      dataViewFirstCellName: '行业'
    }
  },
  computed: {
    title () {
      return this.data.name || '';
    },
    chartOption () {
      return {
        legend: {
          left: 'center',
        },
        grid: {
          containLabel: true,
          left: '5%',
          right: '5%',
          bottom: '6%'
        },
        toolbox: this.chartOptionToolbox,
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          }
        },
        xAxis: {
          type: 'category',
          interval: 0,
          data: this.data.xaxis ? this.data.xaxis.data : []
        },
        yAxis: [
          ...(this.data.series || []).map((item, index) => ({
            type: 'value',
            name: item.unit,
            axisLine: {
              show: true
            },
            position: index === 0 ? 'left' : 'right'
          }))
        ],
        series: [
          ...(this.data.series || []).map(item => ({
            type: 'bar',
            name: item.name,
            // TODO
            yAxisIndex: 0,
            tooltip: {
              valueFormatter: value => `${defaultNumber(value)} ${item.unit}`
            },
            data: item.data || []
          }))
        ]
      }
    }
  },
}
</script>
